﻿using System;  
using System.IO;
using System.Xml.Serialization;
using System.Text;
using seoWebApplication.st.SharkTankDAL.DataCashLib;

namespace seoWebApplication
{
    public partial class DataCashLibTest : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // Prepare StringBuilder for output
            StringBuilder sb = new StringBuilder();
            // Initialize variables
            myWsRequest request;
            XmlSerializer requestSerializer =
            new XmlSerializer(typeof(myWsRequest));
            myWsResponse response;
            XmlSerializer responseSerializer =
            new XmlSerializer(typeof(myWsResponse));
            StringBuilder xmlBuilder;
            StringWriter xmlWriter;
            //string dataCashUrl =
            //"https://testserver.datacash.com/Transaction";
            string myUrl = "http://www.shade4sale.com/webservices/authenticateUser.asmx";
       
            // Construct pre request
            request = new myWsRequest();
             //request.RetProducts.ReturnProducts = "<ReturnProducts xmlns=devArticles />";
             
            // Display pre request
            
            string SOAPPOST = "POST /webservices/authenticateUser.asmx HTTP/1.1";
            sb.AppendLine(SOAPPOST);
            string SOAPHost = "Host: www.shade4sale.com";
            sb.AppendLine(SOAPHost);
            string SOAPContentType = "Content-Type: text/xml; charset=utf-8";
            sb.AppendLine(SOAPContentType);
            string SOAPContentLength = "Content-Length: length";
            sb.AppendLine(SOAPContentLength);
            string SOAPAction = "SOAPAction: \"devArticles/ReturnProducts\"";
            sb.AppendLine(SOAPAction);
            xmlBuilder = new StringBuilder();
            xmlWriter = new StringWriter(xmlBuilder);
            requestSerializer.Serialize(xmlWriter, request);
            sb.AppendLine(xmlBuilder.ToString());
            sb.AppendLine();
            sb.Replace("_x003A_", ":");
            // Get pre response
            response = request.GetResponse(myUrl);
            // Display pre response
            //sb.AppendLine("Pre Response:");
            xmlBuilder = new StringBuilder();
            xmlWriter = new StringWriter(xmlBuilder);
            responseSerializer.Serialize(xmlWriter, response);
            sb.AppendLine(xmlBuilder.ToString());
            sb.AppendLine();
            // Construct fulfil request
            request = new myWsRequest();
            //request.RetProducts.ReturnProducts = "";
            //request.RetProducts.ReturnProducts2 =
            //response.ReturnProductsResult;
             
            // Display fulfil request
            sb.AppendLine("Fulfil Request:");
            xmlBuilder = new StringBuilder();
            xmlWriter = new StringWriter(xmlBuilder);
            requestSerializer.Serialize(xmlWriter, request);
            sb.AppendLine(xmlBuilder.ToString());
            sb.AppendLine();
            // Get fulfil response
            response = request.GetResponse(myUrl);
            // Display fulfil response
            sb.AppendLine("Fulfil Response:");
            xmlBuilder = new StringBuilder();
            xmlWriter = new StringWriter(xmlBuilder);
            responseSerializer.Serialize(xmlWriter, response);
            sb.AppendLine(xmlBuilder.ToString());
            // Output result
            OutputBox.Text = sb.ToString();
        }
    }
}
